﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xiaov.SmartWeb.Infrastructure.ExtMethod;

namespace Xiaov.SmartWeb.Application.PluginSrc.StatisticalSystem
{
    public partial class ExportXls : System.Web.UI.Page
    {
        public string TableName { get; set; }
        public string Year { get; set; }
        public string Month { get; set; }
        public string DWBM { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            TableName = Request.Form["tn"].ToRequestString();
            Year = Request.Form["year"].ToRequestString();
            Month = Request.Form["month"].ToRequestString();
            DWBM = Request.Form["dwbm"].ToRequestString();

            string htmltable = "";
            //将数据形成为Table


            Xiaov.SmartWeb.Model.Statistical.BaseReport baseReport = new Model.Statistical.BaseReport(TableName,DWBM,Year,Month);
            baseReport.InitReport();
           
            System.Text.StringBuilder sb = new System.Text.StringBuilder(Server.UrlDecode(htmltable));
            System.IO.StringWriter oStringWriter = new System.IO.StringWriter(sb);
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
            //this.RenderControl(oHtmlTextWriter);
            Response.Write(@"<html>
<style>
table tr td {
border: 1px solid #000000;
border-collapse:collapse;
}
</style>
        <body>");
            Response.Write(oStringWriter.ToString());
            Response.Write("</body></html>");
            Response.AddHeader("Content-type", "application/application/ms-excel");
            Response.AddHeader("content-disposition", "attachment; filename=\"data.xls\"");
            Response.End();
        }
    }
}